#include "stdafx.h"

#include "BankData.h"

#include "TransactionStoreServer.h"

namespace PC2
{


TransactionStoreServer::TransactionStoreServer( ApplicationSettings* apSettings )
	: m_Part(apSettings->m_NodeInfo, apSettings->m_DBPath.c_str(), apSettings->m_RemoteNodeInfo, apSettings->m_Parts)
	, m_Executor(m_Part.GetDataStore())
{
	printf("TransactionStoreServer %s\n", apSettings->m_NodeInfo.m_Name.c_str());
	m_Part.SetExecutor(&m_Executor);
}

void TransactionStoreServer::Exec()
{
	int cmd;
	while(true)
	{
		printf("1: dump all record, else start\n");
		scanf("%d", &cmd);
		if(1 == cmd)
		{
			std::vector<std::pair<std::string, BankTransaction> > lVec;
			m_Executor.DumpAllTransaction(&lVec);

			for (auto it = lVec.begin(); it != lVec.end(); it++)
			{
				printf("time %s name %s from %s to %s value %u\n",it->first.c_str()
					, it->second.m_Name,it->second.m_BankFrom,it->second.m_BankTo,it->second.m_Value);
			}
		}
		else
		{
			m_Part.Run();
		}
	}
	
}


}